#pragma once

#include "monitor.h"
#include <wlr/types/wlr_scene.h>
#include <wlr/util/box.h>
#include <wlr/types/wlr_xdg_shell.h>

enum { XDGShell, LayerShell, X11Managed, X11Unmanaged }; /* client types */

struct input_popup {
    struct input_method_relay *relay;
    struct wlr_input_popup_surface_v2 *popup_surface;

    struct wlr_scene_node *scene;
    struct wlr_scene_node *scene_surface;

    struct wl_list client_link;

    int x, y;
    bool visible;

    struct wl_listener popup_map;
    struct wl_listener popup_unmap;
    struct wl_listener popup_destroy;
    struct wl_listener popup_surface_commit;
    struct wl_listener focused_surface_unmap;
};

typedef struct {
    const char *id;
    const char *title;
    unsigned int tags;
    int isfloating;
    int monitor;
} Rule;

typedef struct Client {
    /* Must be first */
    unsigned int type; /* XDGShell or X11* */
    struct wlr_scene_node *scene;
    struct wlr_scene_rect *border[4]; /* top, bottom, left, right */
    struct wlr_scene_node *scene_surface;
    struct wl_list link;
    struct wl_list flink;
    struct wl_list input_popups; /* dwl_input_popup::client_link */
    union {
        struct wlr_xdg_surface *xdg;
        struct wlr_xwayland_surface *xwayland;
    } surface;
    struct wl_listener commit;
    struct wl_listener map;
    struct wl_listener unmap;
    struct wl_listener destroy;
    struct wl_listener set_title;
    struct wl_listener fullscreen;
    struct wlr_box geom, prev;  /* layout-relative, includes border */
    Monitor *mon;
    int bw;
    unsigned int tags;
    int isfloating, isurgent;
    uint32_t resize; /* configure serial of a pending resize */
    int isfullscreen;
    Server* server; /*added by biwenjie*/
} Client;


uint32_t client_set_size(Client *c, uint32_t width, uint32_t height);
void client_min_size(Client *c, int *width, int *height);
struct wlr_surface *client_surface(Client *c);
Client *client_from_popup(struct wlr_xdg_popup *popup);
int client_is_unmanaged(Client *c);
void client_get_geometry(Client *c, struct wlr_box *geom);
void client_set_tiled(Client *c, uint32_t edges);
int client_is_float_type(Client *c);
const char *client_get_appid(Client *c);
const char *client_get_title(Client *c);
void client_set_fullscreen(Client *c, int fullscreen);
void client_activate_surface(struct wlr_surface *s, int activated);

void applybounds(Client *c, struct wlr_box *bbox);
void applyrules(Client *c);

void resize(Client *c, int x, int y, int w, int h, int interact);
void setfullscreen(Client *c, int fullscreen);
void focusclient(Client *c, int lift);
Client *focustop(Monitor *m);
void setmon(Client *c, Monitor *m, unsigned int newtags);
void pointerfocus(Client *c, struct wlr_surface *surface, double sx, double sy, uint32_t time);
